package com.yvon.service.demo.spring.factory.support;

import com.yvon.service.demo.spring.BeanException;
import com.yvon.service.demo.spring.factory.config.BeanDefinition;

/**
 * 抽象自动装配bean工厂
 * 根据BeanDefinition创建Bean
 *
 * @author Yvon
 * @since 2022-11-24
 */
public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory{
    @Override
    protected Object createBean(String beanName, BeanDefinition beanDefinition) throws BeanException {
        Object bean = null;
        try {
            bean = beanDefinition.getBeanClass().newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new BeanException("Instantiation of bean failed", e);
        }
        registerSingleton(beanName, bean);
        return bean;
    }
}
